#include<stdio.h>
#include<conio.h>
int a[1000],trace[1000],i,j,n,max,temp,s,d[1000];
void input(){
    FILE *fp=fopen("DAYCON.INP","r");
    fscanf(fp,"%d",&n);
    for(i=1;i<=n;i++)
        fscanf(fp,"%d",&a[i]);
    fclose(fp);
}
void process(){
    max=0;
    for(i=1;i<=n;i++){
        for(j=1;j<i;j++)
            if(d[i]<=d[j] && a[i]>=a[j]){
                d[i]=d[j]+1;
                trace[i]=j;
            }
        if(d[i]>d[max])max=i;
    }
}
void output(){
    printf("%d\n",d[max]);
    do{
        printf("%d ",a[max]);
        max=trace[max];
    }while(max>0);
}
int main(){
    input();
    process();
    output();
    getch();
    return 0;
}
